*Do-File

*Article: Döring and Mustasilta (2023) "Spatial Patterns of Communal Violence in Sub-Saharan Africa" forthcoming in Journal of Peace Research. 

*Here we provide the code to run the main analysis. The results for the tables in the article were generated by using Stata SE 15.1, but they also work on newer software versions. Coefficients and standard errors reported in the article were multiplied by 100 for readibility. Note that depending on the computer, some models might take very long to compute. For the direct, indirect and total effects of some models, a 2018 Mac Air would run between 23 to 35 hours depending on the model.

use "SDKM_data.dta", clear

spmatrix use Wr using "Wr_Sample1.stswm", replace


///// TABLE I


//Model 1 [SEM / We]
spxtregress inci_com i.lexcluded_dum li_pop_hyd_dens li_gcp_ppp li_droughtyr_speibase i.lcivil_act_inci, fe errorlag(Wr)

//Model 2 [SAR / WY]
spxtregress inci_com i.lexcluded_dum li_pop_hyd_dens li_gcp_ppp li_droughtyr_speibase i.lcivil_act_inci, fe dvarlag(Wr)

//Model 3 [SAC / WY, We]
spxtregress inci_com i.lexcluded_dum li_pop_hyd_dens li_gcp_ppp li_droughtyr_speibase i.lcivil_act_inci, fe dvarlag(Wr) errorlag(Wr)
eststo A4

//Model 4 [Not spatial / Dummy variable as WY]
xtreg inci_com i.lexcluded_dum li_pop_hyd_dens li_gcp_ppp li_droughtyr_speibase i.lcivil_act_inci i.Winci_d , fe



///// TABLE II


//Model 5 [SLX / WX]
spxtregress inci_com i.lexcluded_dum li_pop_hyd_dens li_gcp_ppp li_droughtyr_speibase i.lcivil_act_inci, fe ivarlag(Wr: li_pop_hyd_dens li_gcp_ppp li_droughtyr_speibase i.lexcluded_dum i.lcivil_act_inci)


//Model 6 [SDEM / WX We]
spxtregress inci_com i.lexcluded_dum li_pop_hyd_dens li_gcp_ppp li_droughtyr_speibase i.lcivil_act_inci, fe ivarlag(Wr: li_pop_hyd_dens li_gcp_ppp  li_droughtyr_speibase  i.lexcluded_dum i.lcivil_act_inci) errorlag(Wr)

//Model 7 [SDM / WX WY]
spxtregress inci_com i.lexcluded_dum li_pop_hyd_dens li_gcp_ppp li_droughtyr_speibase i.lcivil_act_inci, fe dvarlag(Wr) ivarlag(Wr: li_pop_hyd_dens li_gcp_ppp  li_droughtyr_speibase  i.lexcluded_dum i.lcivil_act_inci)


///// TABLE III

**Indirect, direct effects for SLX (Model 5)
spxtregress i  
estat impact 1.lexcluded_dum li_pop_hyd_dens li_gcp_ppp li_droughtyr_speibase 1.lcivil_act_inci

/*
Average impacts                                 Number of obs     =    193,250

---------------------------------------------------------------------------------------
                      |            Delta-Method
                      |      dy/dx   Std. Err.      z    P>|z|     [95% Conf. Interval]
----------------------+----------------------------------------------------------------
direct                |
        lexcluded_dum |
                   1  |   .0010048   .0014376     0.70   0.485    -.0018129    .0038224
                      |
      li_pop_hyd_dens |  -.0034478   .0034214    -1.01   0.314    -.0101537     .003258
           li_gcp_ppp |  -.0028959   .0018698    -1.55   0.121    -.0065606    .0007688
li_droughtyr_speibase |  -.0029543   .0047225    -0.63   0.532    -.0122102    .0063016
                      |
      lcivil_act_inci |
                   1  |   .0069552   .0013728     5.07   0.000     .0042645    .0096459
----------------------+----------------------------------------------------------------
indirect              |
        lexcluded_dum |
                   1  |   .0002373   .0016551     0.14   0.886    -.0030066    .0034812
                      |
      li_pop_hyd_dens |   .0174934   .0035909     4.87   0.000     .0104555    .0245314
           li_gcp_ppp |   .0007581    .002477     0.31   0.760    -.0040967     .005613
li_droughtyr_speibase |   .0110691   .0056376     1.96   0.050     .0000196    .0221186
                      |
      lcivil_act_inci |
                   1  |   .0081034   .0027079     2.99   0.003      .002796    .0134108
----------------------+----------------------------------------------------------------
total                 |
        lexcluded_dum |
                   1  |   .0012421   .0006892     1.80   0.072    -.0001088    .0025929
                      |
      li_pop_hyd_dens |   .0140456   .0009934    14.14   0.000     .0120985    .0159927
           li_gcp_ppp |  -.0021378   .0013604    -1.57   0.116    -.0048042    .0005286
li_droughtyr_speibase |   .0081148   .0029374     2.76   0.006     .0023576    .0138719
                      |
      lcivil_act_inci |
                   1  |   .0150586   .0025746     5.85   0.000     .0100124    .0201047
---------------------------------------------------------------------------------------
*/


**Indirect, direct effects for SDEM
spxtregress inci_com i.lexcluded_dum li_pop_hyd_dens li_gcp_ppp li_droughtyr_speibase i.lcivil_act_inci, fe ivarlag(Wr: li_pop_hyd_dens li_droughtyr_speibase li_gcp_ppp i.lexcluded_dum i.lcivil_act_inci) errorlag(Wr)
estat impact 1.lexcluded_dum li_pop_hyd_dens li_gcp_ppp li_droughtyr_speibase 1.lcivil_act_inci

/*
Average impacts                                 Number of obs     =    193,250

---------------------------------------------------------------------------------------
                      |            Delta-Method
                      |      dy/dx   Std. Err.      z    P>|z|     [95% Conf. Interval]
----------------------+----------------------------------------------------------------
direct                |
        lexcluded_dum |
                   1  |   .0016674    .001343     1.24   0.214    -.0009649    .0042997
                      |
      li_pop_hyd_dens |  -.0015204    .003161    -0.48   0.631    -.0077159    .0046751
           li_gcp_ppp |  -.0026917   .0017394    -1.55   0.122    -.0061008    .0007174
li_droughtyr_speibase |   -.003096   .0043638    -0.71   0.478    -.0116489    .0054569
                      |
      lcivil_act_inci |
                   1  |   .0072854   .0013086     5.57   0.000     .0047206    .0098503
----------------------+----------------------------------------------------------------
indirect              |
        lexcluded_dum |
                   1  |  -.0006843   .0016857    -0.41   0.685    -.0039881    .0026196
                      |
      li_pop_hyd_dens |   .0151418   .0034601     4.38   0.000     .0083602    .0219234
           li_gcp_ppp |   .0003888    .002595     0.15   0.881    -.0046974     .005475
li_droughtyr_speibase |   .0113172   .0059088     1.92   0.055    -.0002638    .0228982
                      |
      lcivil_act_inci |
                   1  |   .0025304   .0031979     0.79   0.429    -.0037374    .0087983
----------------------+----------------------------------------------------------------
total                 |
        lexcluded_dum |
                   1  |   .0009832   .0009898     0.99   0.321    -.0009568    .0029231
                      |
      li_pop_hyd_dens |   .0136214   .0014611     9.32   0.000     .0107578    .0164851
           li_gcp_ppp |  -.0023029   .0018587    -1.24   0.215    -.0059458      .00134
li_droughtyr_speibase |   .0082212   .0042359     1.94   0.052     -.000081    .0165233
                      |
      lcivil_act_inci |
                   1  |   .0098159   .0033992     2.89   0.004     .0031536    .0164782
---------------------------------------------------------------------------------------
*/




**Indirect, direct effects for SDM
spxtregress inci_com i.lexcluded_dum li_pop_hyd_dens li_gcp_ppp li_droughtyr_speibase i.lcivil_act_inci, fe dvarlag(Wr) ivarlag(Wr: li_pop_hyd_dens li_droughtyr_speibase li_gcp_ppp i.lexcluded_dum i.lcivil_act_inci)
estat impact 1.lexcluded_dum li_pop_hyd_dens li_gcp_ppp li_droughtyr_speibase 1.lcivil_act_inci

/*

Average impacts                                 Number of obs     =    193,250

---------------------------------------------------------------------------------------
                      |            Delta-Method
                      |      dy/dx   Std. Err.      z    P>|z|     [95% Conf. Interval]
----------------------+----------------------------------------------------------------
direct                |
        lexcluded_dum |
                   1  |   .0013744   .0013374     1.03   0.304    -.0012468    .0039955
                      |
      li_pop_hyd_dens |  -.0024348   .0031893    -0.76   0.445    -.0086857    .0038162
           li_gcp_ppp |  -.0026883   .0017337    -1.55   0.121    -.0060863    .0007096
li_droughtyr_speibase |  -.0031004   .0044017    -0.70   0.481    -.0117275    .0055267
                      |
      lcivil_act_inci |
                   1  |   .0071799   .0013106     5.48   0.000     .0046111    .0097486
----------------------+----------------------------------------------------------------
indirect              |
        lexcluded_dum |
                   1  |  -.0002285   .0017491    -0.13   0.896    -.0036566    .0031997
                      |
      li_pop_hyd_dens |   .0164487   .0035384     4.65   0.000     .0095136    .0233838
           li_gcp_ppp |    .000348   .0028253     0.12   0.902    -.0051895    .0058855
li_droughtyr_speibase |   .0117759   .0062147     1.89   0.058    -.0004047    .0239565
                      |
      lcivil_act_inci |
                   1  |   .0059331   .0037328     1.59   0.112     -.001383    .0132492
----------------------+----------------------------------------------------------------
total                 |
        lexcluded_dum |
                   1  |   .0011459   .0010349     1.11   0.268    -.0008824    .0031742
                      |
      li_pop_hyd_dens |   .0140139   .0014917     9.39   0.000     .0110903    .0169375
           li_gcp_ppp |  -.0023404   .0020427    -1.15   0.252     -.006344    .0016633
li_droughtyr_speibase |   .0086755   .0044105     1.97   0.049      .000031    .0173199
                      |
      lcivil_act_inci |
                   1  |    .013113   .0038659     3.39   0.001      .005536    .0206899
---------------------------------------------------------------------------------------
*/
